#include "abstract-database-client.h"
#include "abstract-queries.h"
#include "debug-helper.h"
#include "line-edit-delegate.h"
#include "value-result.h"
#include "warehouse-section-model.h"
#include "warehouse-section-queries.h"

WarehouseSectionModel::WarehouseSectionModel(QObject *parent) :
    StandardDatabaseModel(parent)
{
}

void WarehouseSectionModel::initialize()
{
    m_queries = new WarehouseSectionQueries(this);
    LineEditDelegate* nameDelegate = new LineEditDelegate(this);
    m_delegates.insert(NameColumn, nameDelegate);
    m_headerSections << "Nazwa";
    m_dataAlreadyExistText = "Magazyn o takich danych już istnieje.";
    StandardDatabaseModel::initialize();
}

ValueResult* WarehouseSectionModel::canSetField (QVariant value, int column, int row)
{
    Q_UNUSED(row);
    ValueResult* result = new ValueResult(this);
    if (column == NameColumn)
    {
        QString name(value.toString());
        if (name.isEmpty())
            result->setError("Nazwa magazynu jest pusta.", SmGlobal::DataInvalidError);
        else
            result->setValue(true);
    }
    else
    {
        fatalError(column);
        return 0;
    }
    return result;
}
